﻿using Microsoft.Practices.Unity;
using System;

namespace BalanceManager.Services
{
    public class ContainerService : IDisposable
    {
        private bool disposed;

        public ContainerService()
        {
            this.Container = new UnityContainer();
            this.ConfigureContainer();
        }

        public IUnityContainer Container { get; private set; }

        private void ConfigureContainer()
        {
            this.Container.RegisterType<IDataService, DataService>(new ContainerControlledLifetimeManager());
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                this.Container.Dispose();
            }

            disposed = true;
        }
    }
}
